From d469bbcb16d0bd0231614e4776ff712ee4dcf2ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 13 Jul 2016 19:38:10 +0300 Subject: [PATCH] Add explicit host_triple to BuildConfig --- src/cargo/ops/cargo_clean.rs | 3 ++- src/cargo/ops/cargo_compile.rs | 5 +++-- src/cargo/ops/cargo_rustc/context.rs | 19 ++++++------------- src/cargo/ops/cargo_rustc/mod.rs | 3 ++- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 47aaaa00d..b20559337 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -35,8 +35,9 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { let profiles = try!(ws.current()).manifest().profiles(); let mut cx = try!(Context::new(ws, &resolve, &packages, opts.config, BuildConfig { - release: opts.release, + host_triple: opts.config.rustc_info().host.clone(), requested_target: opts.target.map(|s| s.to_owned()), + release: opts.release, ..BuildConfig::default() }, profiles)); diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 8f175324a..744cc54e9 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -443,11 +443,12 @@ fn scrape_build_config(config: &Config, let cfg_target = try!(config.get_string("build.target")).map(|s| s.val); let target = target.or(cfg_target); let mut base = ops::BuildConfig { - jobs: jobs, + host_triple: config.rustc_info().host.clone(), requested_target: target.clone(), + jobs: jobs, ..Default::default() }; - base.host = try!(scrape_target_config(config, &config.rustc_info().host)); + base.host = try!(scrape_target_config(config, &base.host_triple)); base.target = match target.as_ref() { Some(triple) => try!(scrape_target_config(config, &triple)), None => base.host.clone(), diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 53678eb5b..0736d9fe6 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -42,7 +42,6 @@ pub struct Context<'a, 'cfg: 'a> { host: Layout, target: Option, - target_triple: String, target_info: TargetInfo, host_info: TargetInfo, profiles: &'a Profiles, @@ -71,16 +70,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => None, }; - let target = build_config.requested_target.clone(); - let target = target.as_ref().map(|s| &s[..]); - let target_triple = target.unwrap_or_else(|| { - &config.rustc_info().host[..] - }).to_string(); let engine = build_config.exec_engine.as_ref().cloned().unwrap_or({ Arc::new(Box::new(ProcessEngine)) }); Ok(Context { - target_triple: target_triple, host: host_layout, target: target_layout, resolve: resolve, @@ -138,7 +131,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { try!(self.visit_crate_type(unit, &mut crate_types)); } try!(self.probe_target_info_kind(&crate_types, Kind::Target)); - if self.build_config.requested_target.is_none() { + if self.requested_target().is_none() { self.host_info = self.target_info.clone(); } else { try!(self.probe_target_info_kind(&crate_types, Kind::Host)); @@ -184,7 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { process.arg("--crate-type").arg(crate_type); } if kind == Kind::Target { - process.arg("--target").arg(&self.target_triple); + process.arg("--target").arg(&self.target_triple()); } let mut with_cfg = process.clone(); @@ -266,12 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// Return the host triple for this context pub fn host_triple(&self) -> &str { - &self.config.rustc_info().host[..] + &self.build_config.host_triple } /// Return the target triple which this context is targeting. pub fn target_triple(&self) -> &str { - &self.target_triple + self.requested_target().unwrap_or(self.host_triple()) } /// Requested (not actual) target for the build @@ -376,11 +369,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> { if unsupported.len() > 0 { bail!("cannot produce {} for `{}` as the target `{}` \ does not support these crate types", - unsupported.join(", "), unit.pkg, self.target_triple) + unsupported.join(", "), unit.pkg, self.target_triple()) } bail!("cannot compile `{}` as the target `{}` does not \ support any of the output crate types", - unit.pkg, self.target_triple); + unit.pkg, self.target_triple()); } Ok(ret) } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 3401145f4..204d4d0ad 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -35,10 +35,11 @@ pub enum Kind { Host, Target } #[derive(Default, Clone)] pub struct BuildConfig { + pub host_triple: String, pub host: TargetConfig, + pub requested_target: Option, pub target: TargetConfig, pub jobs: u32, - pub requested_target: Option, pub exec_engine: Option>>, pub release: bool, pub test: bool, -- 2.30.2